/* 登录状态相关的路由 */
var express = require('express')
var router = express.Router()

// 导入db ,操作数据库
const { getAll, getById, exec } = require('../db/index')

/* 根据id或者用户名将用户登录状态修改为上线或者下线 */
// put ('/online/id=1&username='hrl'&online=0)
router.put('/', async (req, res) => {
  const { userid = -1, username = '', online } = req.query
  let sql = `update gg_user set user_onlinestatus=${online} where user_name='${username}' or user_id =${userid}`
  const data = await exec(sql)
  res.send({
    code: 0,
    message: '登录状态一改变',
    result: {
      data,
      userid,
      username,
      online,
    },
  })
})

module.exports = router
